﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TPAMain工序结余锁定工具
{
    public partial class frmLogin : Form
    {
        public frmLogin()
        {
            InitializeComponent();
        }

        private void frmLogin_Load(object sender, EventArgs e)
        {
            cmbUserName.Focus();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (cmbUserName.Text.Equals(string.Empty))
            {
                GeneralTools.ShowInfoMsg("用户名称不能为空！");
                cmbUserName.Focus();
                return;
            }
            UserInfo ui = new UserInfo(cmbUserName.Text, txtPassword.Text);
            if (ui.LoginSuccess)
            {
                if (ui.QueryOnly)
                {
                    frmReport newFrmReport = new frmReport();
                    newFrmReport.Show();
                    this.Close();
                }
                else
                {
                    frmMain newFrmMain = new frmMain(ui);
                    //newFrmMain.WindowState = FormWindowState.Maximized;
                    newFrmMain.Show();
                    this.Close();
                }
            }
            else
            {
                GeneralTools.ShowErrorMsg("登录失败：" + ui.LoginErrMsg);
                return;
            }
        }

        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                btnLogin_Click(this, new EventArgs());
            }
        }
    }
}